// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init()
const db = cloud.database();
// 云函数入口函数
// 删除一个菜谱列表
exports.main = async (event, context) => {
  const wxContext = cloud.getWXContext()

  let classifyId = event.classifyId;
  let type = event.type;

  let classifyRes = await db.collection('classify').doc(classifyId).remove();
  // let classifyRes = await db.collection('classify').doc(classifyId).get();

  let homeListRes = await db.collection("home_list").where({
    type
  }).get();

  let home = null;
  if(homeListRes.data.length){
    home = homeListRes.data[0];
    await db.collection("home_list").doc(home._id).remove();
  }

  return {
    event,
    code:200,
    msg:"删除成功"
    // home,
    // classifyRes,
    // homeListRes,
    // openid: wxContext.OPENID,
    // appid: wxContext.APPID,
    // unionid: wxContext.UNIONID,
  }
}